<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>余额提现</title>
	<link rel="stylesheet" href="normalize-css/normalize.css">
	<link rel="stylesheet" href="css/style.css">
	<script src="js/zepto.min.js"></script>
	<script src="js/judgeBankType.js"></script>
</head>
<body>
	<div class="section withdrawals">
		<div class="card">
			<!-- <select style="width:" class="title text-color-1">
				<option>提现到银行卡</option>
				<option>提现到支付宝</option>
			</select> -->
			<span class="title text-color-1">提现到银行卡</span>
			<a  href="alipayBal" style="float:right;font-size:10px;">点击更换提现到支付宝账户</a>
			<a href="selectBankCard">
				<div class="option-item panel">
					<span class="text-color-1"><span class="carInfoName">工商银行</span>（<span class="carInfoNum">6498</span>）</span>
					<img class="arrow"  src="img/go.png" alt="">
				</div>
			</a>
			<div class="input-item-large">
				<div class="input-item-wrap">
					<label for="price">提现金额</label>
				<span class="price-icon">¥</span>
				<input type="number" name="price" id="price">
				</div>
				<span class="note">最多可提现金额为¥<span class="balance">1200.00</span></span>
			</div>
			<button>提现</button>
		</div>
	</div>
</body>
</html>
<script>
$(document).ready(function(){

	//获取银行卡信息
	var getDefaultCardURL = "./json/myBankCard.json";
	//发出余额提现的post请求，提交参数，银行卡id + 金钱数balance
	var withdrawlsURL = "/withdrawls";


	$(".balance").text(sessionStorage.balance);
	$.get(getDefaultCardURL,function(res) {
		if(res.serviceResult){
			var data = res.resultParm.list;
			if(sessionStorage.cardId===undefined){
				var str = data[0].number;
				$(".carInfoName").text(bankName(data[0].bank));
				$(".carInfoNum").text(str.substring(str.length-4,str.length));
				sessionStorage.cardId = data[0].id;
			}
			else {
				var index;
				for (var i = 0; i < data.length; i++) {
					if(data[i].id==sessionStorage.cardId){
						index = i;break;
					}
				}
				$(".carInfoName").text(bankName(data[index].bank));
				var str = data[index].number;
				$(".carInfoNum").text(str.substring(str.length-4,str.length));
			}
		}
	})
	$("button").click(function(){
		var money = parseInt($("#price").val());
		if(money<=parseInt(sessionStorage.balance) && money!=""){
			$.post(withdrawlsURL,{
				balance:money,
				id:sessionStorage.cardId
			},function(res){
				alert(res.resultInfo);
				// if(res.serviceResult){history.back();}
			});
		}
		else {
			alert("最多提现"+sessionStorage.balance+"元");
		}
	});
});
</script>
